#encoding:utf8
from weibo import APIClient

APP_KEY = '4029247573'
APP_SECRET = 'fc0a6dc9b30355512f1cc70088f8b71b'
CALLBACK_URL = 'http://localhost:8080/gmps/sinaMessAction.action?method=getSinaMess'
'''
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
url = client.get_authorize_url()

print url
'''
code = '57d3e53a50a88a5246155a488ac52859'
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
r = client.request_access_token(code)

access_token = r.access_token # 新浪返回的token，类似abc123xyz456
expires_in = r.expires_in # token过期的UNIX时间：http://zh.wikipedia.org/wiki/UNIX%E6%97%B6%E9%97%B4
#access_token = '2.001eNMHCF3_g5E5f15b534cc0C2fzP'
#expires_in = 1343295229
print access_token, expires_in
# TODO: 在此可保存access token
client.set_access_token(access_token, expires_in)
#print  type(client.get.statuses__user_timeline())
#print client.post.statuses__update(status=u'测试OAuth 2.0发微博')
#print client.__dict__
uid = client.get.account__get_uid()
#print client.get.friendships__friends()
print uid
